package com.xiongwei.singleton;

/**
 * 懒汉式（syncronize线程安全） 实际开发中不推荐
 * 使用同步方法解决线程安全问题
 *
 * 优点：线程安全
 * 缺点：每个线程想要获取类的实例时，都要进行同步，效率太低
 */
public class LazyMan2 {

    private static LazyMan2 instance;

    private LazyMan2() {
        System.out.println("LazyMan2");
    }

    public static synchronized LazyMan2 getInstance() {
        if(instance == null) {
            instance = new LazyMan2();
        }
        return instance;
    }
}
